Ext.define('dg.view.usuarios.PanelUsuarios', {
    extend: 'Ext.panel.Panel',
	
	title:'Usuarios',
	
	alias:'widget.panelusuarios',
	
	//html:'cuerpo de usuarios',
	closable: true,
	
	initComponent: function (){
	
		//this.title='Yo mando';
		Ext.apply( this, {
            layout:'fit',
			//title:' Yo mando'
			tbar:[{
				text:'Agregar usuario',
				iconCls:'add_green_plus_icon',
				scope: this,
				handler: function (boton){
					this.fireEvent("agregar",this, boton,"Agregar");
				}
			},{
				text:'Editar usuario',
				iconCls:'edit_pen_pencil_write_icon',
				scope: this,
				handler: function (boton){
					this.fireEvent("editar",this, boton, "Editar", Ext.getCmp('gridusers').getSelectionModel( ).getLastSelected( ));
				}
			},{
				text:'Eliminar usuario',
				iconCls:'add_cross_delete_edit_exit_remove_icon',
                scope: this,
                handler: function (){
                    var reco= Ext.getCmp('gridusers').getSelectionModel( ).getLastSelected( );
                    console.info(reco);
                    Ext.Msg.confirm( 'Eliminar usuario','Estas seguro que quiere eliminar al usuario seleccionado?',
                        function(btn, text){
                            //console.info(btn);
                            //console.info(text);
                            if (btn == 'yes'){
                            // process text value and close...
                                console.info( this.title );
                                /*Ext.Ajax.request({
                                    url:'index.php/usuario/eliminar',
                                    params:{
                                        id:reco.data.id_usuario
                                    },
                                    scope: this,
                                    success: function (){
                                        console.info("Exito en "+ this.title );
                                    }
                                });*/
                                reco.destroy();
                            }
                    },this);

                }
			},'-','<b>Buscar:</b>',{
				xtype:'combousuarios',
				width:250,
				emptyText:'Ingresa nombre de usuario...'
			}],
            items:{
                xtype:'gridusuarios',
                id:'gridusers',
                listeners:{
                    render: function (g){
                        g.store.load();
                    },

                    itemclick: function (g, record){
                        console.info( record.data);
                    }
                }
            }
		});  
		
		this.callParent(arguments);
		
		//this.addEvents("agregar");
		/*
		this.on({
		
			/* Creacion y renderizado * /
			added: function (){ console.info("added");},
			beforeactivate: function (){ console.info("beforeactivate");},
			beforerender: function (){ console.info("beforerender");},
			render: function (){ console.info("render");},
			afterrender: function (){ console.info("afterrender");},
			beforeshow: function (){ console.info("beforeshow");},
			show: function (){ console.info("show");},
			activate: function (){ console.info("activate");},
			boxready: function (){ console.info("boxready");},
			resize: function (){ console.info("resize");},
			afterlayout: function (){ console.info("afterlayout");},
			
			
			
			
			
			add:function (){ console.info("add");},
			
			
			
		
			beforeadd: function (){ console.info("beforeadd");},
			beforeclose: function (){ console.info("beforeclose");},
			beforecollapse: function (){ console.info("beforecollapse");},
			beforedeactivate: function (){ console.info("beforedeactivate");},
			beforedestroy: function (){ console.info("beforedestroy");},
			beforeexpand: function (){ console.info("beforeexpand");},
			beforehide: function (){ console.info("beforehide");},
			beforeremove: function (){ console.info("beforeremove");},
			
			
			beforestaterestore: function (){ console.info("beforestaterestore");},
			beforestatesave: function (){ console.info("beforestatesave");},
			blur: function (){ console.info("blur");},
			bodyresize: function (){ console.info("bodyresize");},
			
			close: function (){ console.info("close");},
			collapse: function (){ console.info("collapse");},
			deactivate: function (){ console.info("deactivate");},
			destroy: function (){ console.info("destroy");},
			disable: function (){ console.info("disable");},
			enable: function (){ console.info("enable");},
			expand: function (){ console.info("expand");},
			focus: function (){ console.info("focus");},
			hide: function (){ console.info("hide");},
			iconchange: function (){ console.info("iconchange");},
			iconclschange: function (){ console.info("iconclschange");},
			move: function (){ console.info("move");},
			remove: function (){ console.info("remove");},
			removed: function (){ console.info("removed");}
		
			
			
		});*/
	}
	
});